//
// Created by user on 2022/3/7.
//
#include <string>
#include <vector>
using namespace std;
bool checkInclusion(string s1, string s2) {
    int n = s1.size();
    int m = s2.size();
    if(n>m)return false;
    vector<int> cnt(26, 0);

    for (int i = 0; i < n; ++i) {
        cnt[s1[i]-'a']++;
    }

    int left =0;
    int right=0;
    while (right<m){
        char curChar = s2[right];
        int curCharIndex = curChar-'a';
        cnt[curCharIndex]--;
        while (cnt[curCharIndex]<0){
            //通过缩减窗口使得cnt[currCharIndex]不为负数
            cnt[s2[left]-'a']++;
            left++;
        }
        if(right-left+1==n)return true;
        right++;
    }
    return false;
}